package android.example;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

public class Da_A extends Activity {
	private static final int MENU_ITEM0 = 0;
	private static final int MENU_ITEM1 = 1;
	private static final int MENU_ITEM2 = 2;
	private static final int MENU_ITEM3 = 3;
	private static final int MENU_ITEM4 = 4;
	private static final int MENU_ITEM5 = 5;
	private static final int MENU_ITEM6 = 6;
	private static final int MENU_ITEM7 = 7;
	private static final int MENU_ITEM8 = 8;
	
	private ImageButton ibt1;
	private ImageButton ibt2;
	private ImageButton ibt3;
	private ImageButton ibt4;
	private ImageButton ibt5;
	private ImageButton ibt6;
	
	ImageView iv;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        startActivity(new Intent(Da_A.this, Intro.class));
        initialize();
        
        iv=(ImageView)findViewById(R.id.feel);
        iv.setOnCreateContextMenuListener(this);
        
        /*
         * 이미지 버튼 클릭시 각 해당화면으로 넘어가는 부분을 구현 
         */
        ibt1=(ImageButton)findViewById(R.id.note_bt);
        ibt1.setOnClickListener(new Button.OnClickListener() {
        	public void onClick(View v) {
        		Intent intent = new Intent(Da_A.this, Note.class);        		
        		//intent.putExtra("key", "hahaha");     		        		
        		startActivity(intent);        		
        	}
        });
        ibt2=(ImageButton)findViewById(R.id.contact_bt);
        ibt2.setOnClickListener(new Button.OnClickListener() {
        	public void onClick(View v) {
        		//Intent intent = new Intent(Da_A.this, Note.class);        		
        		//intent.putExtra("key", "hahaha");     		        		
        		//startActivity(intent);        		
        	}
        });
        ibt3=(ImageButton)findViewById(R.id.map_bt);
        ibt3.setOnClickListener(new Button.OnClickListener() {
        	public void onClick(View v) {
        		Intent intent = new Intent(Da_A.this, Map.class);        		
        		//intent.putExtra("key", "hahaha");     		        		
        		startActivity(intent);        		
        	}
        });
        ibt4=(ImageButton)findViewById(R.id.calendar_bt);
        ibt4.setOnClickListener(new Button.OnClickListener() {
        	public void onClick(View v) {
        		Intent intent = new Intent(Da_A.this, CalendarDiary.class);        		
        		//intent.putExtra("key", "hahaha");     		        		
        		startActivity(intent);        		
        	}
        });
        ibt5=(ImageButton)findViewById(R.id.bookmark_bt);
        ibt5.setOnClickListener(new Button.OnClickListener() {
        	public void onClick(View v) {
        		//Intent intent = new Intent(Da_A.this, Note.class);        		
        		//intent.putExtra("key", "hahaha");     		        		
        		//startActivity(intent);        		
        	}
        });
        ibt6=(ImageButton)findViewById(R.id.picture_bt);
        ibt6.setOnClickListener(new Button.OnClickListener() {
        	public void onClick(View v) {
        		//Intent intent = new Intent(Da_A.this, Note.class);        		
        		//intent.putExtra("key", "hahaha");     		        		
        		//startActivity(intent);        		
        	}
        });
        
        
    }
    /**
     * 스플래시 표시하는 것과 초기화를 동시에 진행시키기 위하여 쓰레드 처리
     *
     */
    private void initialize()
    {
        InitializationRunnable init = new InitializationRunnable();
        new Thread(init).start();
    }
    class InitializationRunnable implements Runnable{
    	public void run(){
    		for (int i=0; i<5;i++)
			{
				try
				{
					Thread.sleep(1000);
					
					// LogCat?
					Log.d("SPLASH", "------------- initialize..........");
				}
				catch (InterruptedException e)
				{
					e.printStackTrace();
				}
			}

    	}
    }
    
    /*
     * context menu
     */
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo){
    	super.onCreateContextMenu(menu, v, menuInfo);
    	menu.add(0, MENU_ITEM0, 0, "shy");
    	menu.add(0, MENU_ITEM1, 0, "hihi");
    	menu.add(0, MENU_ITEM2, 0, "fantastic");
    	menu.add(0, MENU_ITEM3, 0, "puhaha");
        menu.add(0, MENU_ITEM4, 0, "smile");
        menu.add(0, MENU_ITEM5, 0, "T.*");
        menu.add(0, MENU_ITEM6, 0, "T.T");
        menu.add(0, MENU_ITEM7, 0, "upset");
        menu.add(0, MENU_ITEM8, 0, "angry");
        
    	//menu.add(0, 0, 0, "item0");
    	//menu.add(0, 0, 1, "item1");
    	//menu.add(0, 0, 2, "item2");
    	
    }
    public boolean onContextItemSelected(MenuItem item){
    	//AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
    	
    	switch(item.getItemId()){
    	//setImageResource(R.drawable.arrow_big_green);
    		case MENU_ITEM0:
    			iv.setImageResource(R.drawable.s_1);
    			return true;
    		case MENU_ITEM1:
    			iv.setImageResource(R.drawable.s_2);
    			return true;
    		case MENU_ITEM2:
    			iv.setImageResource(R.drawable.s_3);
    			return true;
    		case MENU_ITEM3:
    			iv.setImageResource(R.drawable.s_4);
    			return true;
    		case MENU_ITEM4:
    			iv.setImageResource(R.drawable.s_5);
    			return true;
    		case MENU_ITEM5:
    			iv.setImageResource(R.drawable.s_6);
    			return true;
    		case MENU_ITEM6:
    			iv.setImageResource(R.drawable.s_7);
    			return true;
    		case MENU_ITEM7:
    			iv.setImageResource(R.drawable.s_8);
    			return true;
    		case MENU_ITEM8:
    			iv.setImageResource(R.drawable.s_9);
    			return true;
    	}
    	return false;
    	//Toast.makeText(this, "item"+item.getItemId()+" selected!", Toast.LENGTH_SHORT).show();
    	//return true;
    }
}